//
//  TopicListHeaderView.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/11.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TopicListHeaderView.h"

@implementation TopicListHeaderView

+ (CGFloat)calculateHeightWithModel:(ProClassificationModel *)model {
    
    CGFloat imageHeight = 110;
    CGFloat textHeight = [Utilities getStringHeightWithText:model.remark font:[UIFont systemFontOfSize:15] viewWidth:(TTScreenWidth - 28)];
    
    CGFloat segHeight = 40;

    return imageHeight + 14 + textHeight + segHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];

    [self.hotestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.newestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    
    self.hotSlide.hidden = NO;
    self.newestSlide.hidden = YES;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mainImageView pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}

- (void)fillWithModel:(ProClassificationModel *)model {
    
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.mainTitleLab.text = [NSString stringWithFormat:@"#%@#",model.parentName];
    self.countLab.text = [NSString stringWithFormat:@"讨论：%@条",model.level];
    self.contentLab.text = model.remark;
    

}

- (IBAction)hotAction:(id)sender {
    
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];

    [self.hotestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.newestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];
    
    self.hotSlide.hidden = NO;
    self.newestSlide.hidden = YES;
    
    if (self.TopicListHeaderViewBlock) {
        self.TopicListHeaderViewBlock(TopicListHeaderActionType_hot);
    }
}

- (IBAction)newAction:(id)sender {
    
    self.hotSlide.hidden = YES;
    self.newestSlide.hidden = NO;

    [self.newestBtn setTitleColor:UIColorHex(0x222222) forState:UIControlStateNormal];
    [self.hotestBtn setTitleColor:UIColorHex(0x333333) forState:UIControlStateNormal];

    self.newestBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    self.hotestBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    
    if (self.TopicListHeaderViewBlock) {
        self.TopicListHeaderViewBlock(TopicListHeaderActionType_new);
    }
}

@end
